{%TEMPLATE->struct/head%}
{%TEMPLATE->struct/menu%}
<h2>New preconfigured task</h2>
{%TEMPLATE->struct/messages%}
<form class='form-inline' action="pretasks.php" method="POST" enctype="multipart/form-data">
  <div class="row" style="width: 110%">
	  <div class='col-md-8'>
		  <input type='hidden' name='action' value='[[$DPretaskAction::CREATE_TASK]]'>
      <input type="hidden" name="csrf" value="[[csrf]]">
		  <div class="card">
        <div class="table-responsive">
          <table class="table table-bordered">
				    <tr>
					    <th>Property</th>
					    <th>Value</th>
				    </tr>
				    <tr>
					    <td>Name:</td>
					    <td>
						    <input type="text" class='form-control full-width' name="name" title="Name" value="[[copy.getTaskName()]]">
					    </td>
				    </tr>
				    <tr>
					    <td>Command line:</td>
					    <td>
                <textarea name="cmdline" class='form-control full-width my-1' id="cmdLine" title="Attack Command">[[copy.getAttackCmd()]]</textarea>
      					Use <b>[[config.getVal([[$DConfig::HASHLIST_ALIAS]])]]</b> for hash list and assume all files in current directory.<br>
      					If you have Linux agents, please mind the filename case sensitivity!
      		    </td>
      	    </tr>
      		  <tr>
      			  <td>Color:</td>
      			  <td>
      				  #<input type="text" class='form-control color {required:false}' name="color" size="6" title="Color" value="[[copy.getColor()]]">
      			  </td>
      		  </tr>
      		  <tr>
      			  <td>Chunk size:</td>
      			  <td>
      				  <input type="text" class='form-control' name="chunk" title="Chunk Size" value="[[copy.getChunkTime()]]"> seconds
      			  </td>
      		  </tr>
      		  <tr>
      			  <td>Status timer:</td>
      			  <td>
      				  <input type="text" class='form-control' name="status" title="Status Timer" value="[[copy.getStatusTimer()]]"> seconds
      			  </td>
      		  </tr>
					  <tr>
						  <td>Benchmark Type (Hashcat only): </td>
						  <td>
                <select name="benchType" class="form-control" title="benchmarkType">
                  <option value="0" {{IF [[copy.getUseNewBench()]] == 0}} selected{{ENDIF}}>Runtime Benchmark</option>
                  <option value="1" {{IF [[copy.getUseNewBench()]] == 1}} selected{{ENDIF}}>Speed Test</option>
                </select>
						  </td>
					  </tr>
            <tr>
              <td>Task is CPU only (gets only CPU agents assigned):</td>
              <td>
                <select name="cpuOnly" class="form-control" title="CPU Only">
                  <option value="0" {{IF [[copy.getIsCpuTask()]] == 0}} selected{{ENDIF}}>No</option>
                  <option value="1" {{IF [[copy.getIsCpuTask()]] == 1}} selected{{ENDIF}}>Yes</option>
                </select>
              </td>
            </tr>
            <tr>
              <td>Task is small (only one agent gets assigned to it):</td>
              <td>
                <select name="isSmall" class="form-control" title="Small Task">
                  <option value="0" {{IF [[copy.getIsSmall()]] == 0}} selected{{ENDIF}}>No</option>
                  <option value="1" {{IF [[copy.getIsSmall()]] == 1}} selected{{ENDIF}}>Yes</option>
                </select>
              </td>
            </tr>
            <tr>
              <td>Cracker Binary which is used to run this task:</td>
              <td>
                <select name="crackerBinaryTypeId" class="form-control" title="Cracker Binary">
                  {{FOREACH binary;[[crackerBinaryTypes]]}}
                    <option value="[[binary.getId()]]" {{IF [[binary.getId()]] == [[copy.getCrackerBinaryTypeId()]]}} selected{{ENDIF}}>[[binary.getTypeName()]]</option>
                  {{ENDFOREACH}}
                </select>
              </td>
            </tr>
      		  <tr>
      			  <td colspan="2" class="text-center">
      				  <input type="submit" class='btn btn-success' value="Create preconfigured task">
      			  </td>
      		  </tr>
			     </table>
        </div>
		  </div>
	  </div>
    <div class='col-md-4'>
      <div class='btn-toolbar my-1'>
        <div class='btn-group'>
          <button id="ruleButton" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}' onclick="return toggleFiles('rules')">Rules</button>
          <button id="wordlistButton" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} active' onclick="return toggleFiles('wordlists')">Wordlists</button>
          <button id="otherButton" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}' onclick="return toggleFiles('other')">Other</button>
        </div>
      </div>
      <div id="rules">
        <div class="card">
          <div class="table-responsive">
            <table class="table table-bordered">
              <tr>
                <th>Filename</th>
                <th>Size</th>
              </tr>
              {{FOREACH file;[[rules]]}}
                <tr>
                  <td>
                    <input title="Add File" type="checkbox" name="adfile[]" value="[[file.getVal('file').getId()]]" onChange="assignFile('cmdLine',this.checked,'[[file.getVal('file').getFilename()]]', 'rule');" {{IF [[file.getVal('checked')]] == 1}} checked{{ENDIF}}{{IF ![[accessControl.hasPermission([[$DAccessControl::CREATE_TASK_ACCESS]])]]}} disabled{{ENDIF}}>
                    [[file.getVal('file').getFilename()]]
                    {{IF [[file.getVal('file').getIsSecret()]] == 1}}
                      <span class="fas fa-lock" aria-hidden="true"></span>
                    {{ENDIF}}
                  </td>
                  <td>
                    [[Util::nicenum([[file.getVal('file').getSize()]])]]B
                  </td>
                </tr>
              {{ENDFOREACH}}
            </table>
          </div>
        </div>
      </div>
      <div id="wordlists">
        <div class="card">
          <div class="table-responsive">
            <table class="table table-bordered">
              <tr>
                <th>Filename</th>
                <th>Size</th>
              </tr>
              {{FOREACH file;[[wordlists]]}}
              <tr>
                <td>
                  <input title="Add File" type="checkbox" name="adfile[]" value="[[file.getVal('file').getId()]]" onChange="assignFile('cmdLine',this.checked,'[[file.getVal('file').getFilename()]]', 'wordlist');" {{IF [[file.getVal('checked')]] == 1}} checked{{ENDIF}}{{IF ![[accessControl.hasPermission([[$DAccessControl::CREATE_TASK_ACCESS]])]]}} disabled{{ENDIF}}>
                  [[file.getVal('file').getFilename()]]
                  {{IF [[file.getVal('file').getIsSecret()]] == 1}}
                    <span class="fas fa-lock" aria-hidden="true"></span>
                  {{ENDIF}}
                </td>
                <td>
                  [[Util::nicenum([[file.getVal('file').getSize()]])]]B
                </td>
              </tr>
              {{ENDFOREACH}}
            </table>
          </div>
        </div>
      </div>
      <div id="other">
        <div class="card">
          <div class="table-responsive">
            <table class="table table-bordered">
              <tr>
                <th>Filename</th>
                <th>Size</th>
              </tr>
              {{FOREACH file;[[other]]}}
              <tr>
                <td>
                  <input title="Add File" type="checkbox" name="adfile[]" value="[[file.getVal('file').getId()]]" onChange="assignFile('cmdLine',this.checked,'[[file.getVal('file').getFilename()]]', 'other');" {{IF [[file.getVal('checked')]] == 1}} checked{{ENDIF}}{{IF ![[accessControl.hasPermission([[$DAccessControl::CREATE_TASK_ACCESS]])]]}} disabled{{ENDIF}}>
                  [[file.getVal('file').getFilename()]]
                  {{IF [[file.getVal('file').getIsSecret()]] == 1}}
                    <span class="fas fa-lock" aria-hidden="true"></span>
                  {{ENDIF}}
                </td>
                <td>
                  [[Util::nicenum([[file.getVal('file').getSize()]])]]B
                </td>
              </tr>
              {{ENDFOREACH}}
            </table>
          </div>
        </div>
      </div>
      <script type='text/javascript'>
        toggleFiles('wordlists');

        function toggleFiles(show) {
          var wordlist = document.getElementById('wordlists');
          var rule = document.getElementById('rules');
          var other = document.getElementById('other');
          if (show === 'rules') {
            wordlist.style.visibility = "hidden"; // or
            wordlist.style.display = "none";
            other.style.visibility = "hidden"; // or
            other.style.display = "none";
            rule.style.visibility = "visible"; // or
            rule.style.display = "inline";
            document.getElementById("ruleButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} active";
            document.getElementById("wordlistButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
            document.getElementById("otherButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
          }
          else if (show === 'wordlists') {
            wordlist.style.visibility = "visible"; // or
            wordlist.style.display = "inline";
            rule.style.visibility = "hidden"; // or
            rule.style.display = "none";
            other.style.visibility = "hidden"; // or
            other.style.display = "none";
            document.getElementById("ruleButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
            document.getElementById("wordlistButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} active";
            document.getElementById("otherButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
          }
          else if (show === 'other') {
            other.style.visibility = "visible"; // or
            other.style.display = "inline";
            rule.style.visibility = "hidden"; // or
            rule.style.display = "none";
            wordlist.style.visibility = "hidden"; // or
            wordlist.style.display = "none";
            document.getElementById("ruleButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
            document.getElementById("wordlistButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}";
            document.getElementById("otherButton").className = "btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} active";
          }
          return false;
        }

        function assignFile(cmdLine, addObject, fileName, type) {
          if (fileName.indexOf('.7z') !== -1) {
            fileName = fileName.substring(0, fileName.length - 2) + '???';
          }
          var cmdObject = document.getElementById(cmdLine);
          if (addObject === true) {
            if (cmdObject.value.indexOf(fileName) === -1) {
              if (cmdObject.value.length > 0 && cmdObject.value.slice(-1) !== ' ') {
                cmdObject.value += ' ';
              }
              if (type === 'rule') {
                cmdObject.value += '-r ';
              }
              cmdObject.value += fileName;
            }
          }
          else {
            if (type === 'rule') {
              cmdObject.value = cmdObject.value.replace('-r ' + fileName, '');
            }
            cmdObject.value = cmdObject.value.replace(fileName, '');
            while (cmdObject.value.slice(-1) === ' ') {
              cmdObject.value = cmdObject.value.substring(0, cmdObject.value.length - 1);
            }
            while (cmdObject.value.substring(0, 1) === ' ') {
              cmdObject.value = cmdObject.value.substring(1);
            }
          }
        }
      </script>
    </div>
  </div>
</form>
{%TEMPLATE->struct/foot%}
